package com.nbsaas.boot.app.rest.convert;

import com.nbsaas.boot.app.api.domain.request.AppMenuRequest;
import com.nbsaas.boot.app.data.entity.App;
import com.nbsaas.boot.app.data.entity.AppMenu;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;

/**
 * 菜单请求对象转换成实体对象
 */

public class AppMenuEntityConvert implements Converter<AppMenu, AppMenuRequest> {

    @Override
    public AppMenu convert(AppMenuRequest source) {
        AppMenu result = new AppMenu();
        BeanDataUtils.copyProperties(source, result);
        if (source.getApp() != null) {
            App app = new App();
            app.setId(source.getApp());
            result.setApp(app);
        }
        if (source.getParent() != null) {
            AppMenu parent = new AppMenu();
            parent.setId(source.getParent());
            result.setParent(parent);
        }
        return result;
    }
}

